package clientapp;

import java.io.IOException;
import java.net.ConnectException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author paciks
 */
public class ClientConnection {

    private Socket clientSocket;
    private int port = 13667;
    private String ip = "localhost";
    public ConnectionHandler connectionHandler;

    public ClientConnection() {
        //this.port = port;
    }

    public void connect() throws IOException, UnknownHostException, ConnectException {
        try {
            System.out.println("Connecting ...");
            clientSocket = new Socket(ip, port);
            connectionHandler = new ConnectionHandler(clientSocket);
            Thread t = new Thread(connectionHandler);
            t.start();
            System.out.println("Connected on port: " + port);
        } catch (UnknownHostException ex) {
            Logger.getLogger(ClientConnection.class.getName()).log(Level.SEVERE, null, ex);
            //   System.exit(-1);
            throw ex;
        } catch (IOException ex) {
            Logger.getLogger(ClientConnection.class.getName()).log(Level.SEVERE, null, ex);
            //  System.exit(-1);
            throw ex;
        }
    }
}
